package com.hey.baseapplication.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hey.baseapplication.R;
import com.hey.baseapplication.api.ApiService;
import com.hey.baseapplication.bean.Event;
import com.hey.baseapplication.bean.EventApi;
import com.hey.baseapplication.presenter.MFPresenter;
import com.hey.baseapplication.view.IMFView;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import java.util.List;

public class MainFragment extends BaseFragment<MFPresenter> implements IMFView {
    private View mView;
    private RecyclerView mRecyclerView;
    private EventApi eventApi;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_main, container, false);
        initPresenter(new MFPresenter(this));
        initView();
        return mView;
    }

    public void initView() {
        mRecyclerView = (RecyclerView) mView.findViewById(R.id.event_list);
        eventApi = new EventApi();
        eventApi.setAccess_token(ApiService.ACCESS_TOKEN);
        eventApi.setIs_all("1");
        presenter.getData();

    }

    @Override
    public EventApi getEventApi() {
        return eventApi;
    }

    @Override
    public void setData(List<Event> events) {
       CommonAdapter<Event> adapter=new CommonAdapter<Event>(getContext(),R.layout.item_event,events) {
           @Override
           protected void convert(ViewHolder holder, Event event, int position) {
                holder.setText(R.id.event_title,event.getId());
           }
       };
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecyclerView.setAdapter(adapter);
        mRecyclerView.setOnFlingListener(new RecyclerView.OnFlingListener() {
            @Override
            public boolean onFling(int velocityX, int velocityY) {


                return false;
            }
        });
    }

    @Override
    public void onError(Throwable e) {

    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }



    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void next() {

    }

}
